<template>
  <div>
    <!-- 搜索 -->
    <!-- 旧件回运仓库维护-按下线工厂 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams" :fetchapi="fetchapi"  :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange">
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-check" :click="qiyong.bind()">启用</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-close" :click="tingyong.bind()">禁用</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">下载</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-plus" :click="exportFileBtn.bind()">导出模版</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">数据导入</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visibleAdd" :title="'旧件回运仓库维护-按下线工厂新增'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <AddForm @close="closeAdd" @save="saveAdd"></AddForm>
    </BaseDialog>
    <BaseDialog :visible.sync="visibleEdit" :title="'旧件回运仓库维护-按下线工厂编辑'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <EditForm @close="closeEdit" @save="saveEdit" :rowData="rowData" ></EditForm>
    </BaseDialog>
  </div>
</template>
<script>
import { getListByPage, newSave, piliangqiyong, piliangtingyong, excelExport, editSave } from '@/api/claim/factory/ReturnWhMaintainFactory';
import Vehicle from './FactoryVehicle.vue';
import AddForm from './AddForm.vue';
import EditForm from './EditForm.vue';
export default {
  // mixins: [dictionary],
  components: {
    Vehicle,
    AddForm,
    EditForm
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
       rowData: {},
      infoId: null,
      fetchapi: getListByPage,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      // fetchApi: getUser,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '配件选择',
      visibleAdd: false,
      visibleEdit: false
    };
  },
  created() {
    // this.dataList = [...res.data.items];
    console.log(this.dataList);
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    chooseOrderNo() {
      this.visible = true;
    },
    //批量启用
    async qiyong() {
      console.log(this.selectedRows);
      let str = '';
      this.selectedRows.map(x => {
        str += x.facId + ',';
      });
      console.log(str);
      const res = await piliangqiyong({ ids: str, status: '1' });
    },
    //批量停用
    async tingyong() {
      console.log(this.selectedRows);
      let str = '';
      this.selectedRows.map(x => {
        str += x.facId + ',';
      });
      console.log(str);
      const res = await piliangtingyong({ids: str, status: '0'});
    },
    exportFileBtn() {
      this.$refs.TopFilterss.SUBMIT_FORM();
    },
    add() {
      this.visibleAdd = true;
    },
    edit() {
      this.visibleEdit = true;
    },
    closeAdd() {
      this.visibleAdd = false;
      this.fetchParams = {...this.fetchParams};
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = {...this.fetchParams};
    },
    closeEdit() {
      this.visibleEdit = false;
      this.fetchParams = {...this.fetchParams};
    }, emitFun(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    saveEdit() {
      this.visibleEdit = false;
      this.fetchParams = {...this.fetchParams};
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '工厂代码', fieldName: 'facCode', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '工厂名称', fieldName: 'facName', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '仓库代码', fieldName: 'whCode', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '仓库名称', fieldName: 'whName', placeholder: '请输入', initialValue: '' },
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button type="text" onClick={() => this.emitFun(props.row)} >
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        { title: '状态', dataIndex: 'wfStatus', sorter: true },
        { title: '仓库名称', dataIndex: 'whName', sorter: true },
        { title: '仓库代码', dataIndex: 'whCode', sorter: true },
        { title: '工厂名称', dataIndex: 'facCode', sorter: true },
        { title: '工厂代码', dataIndex: 'facName', sorter: true },
        { title: '创建人', dataIndex: 'createdBy', sorter: true },
        { title: '创建时间', dataIndex: 'createdAt', sorter: true },
        { title: '修改人', dataIndex: 'updatedBy', sorter: true },
        { title: '修改时间', dataIndex: 'updatedAt', sorter: true }
      ];
    }
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
